define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'show/index' + location.search,
                    /*add_url: 'show/add',
                    edit_url: 'show/edit',*/
                    del_url: 'show/del',
                    multi_url: 'show/multi',
                    import_url: 'show/import',
                    table: 'show',
                }
            });

            var table = $("#table");

            table.on('load-success.bs.table', function (e, data) {
                $('label[for="connection_id"]').parent().css('display','none'); // 隐藏学校搜索栏
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                search:false,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'type_data', title: __('Type_data'), searchList: {"0":__('Type_data 0'),"1":__('Type_data 1')}, formatter: Table.api.formatter.normal},
                        {field: 'connection_id', title: __('Connection_id'), operate: '=',visible:false},
                        {field: 'connection_name', title: __('Connection_name'), operate: 'LIKE'},
                        {field: 'connection_mobile', title: __('Connection_mobile'), operate: 'LIKE',formatter: function (row,index) {
                                return index.connection_mobile_see
                            }},
                        {field: 'connection_mobile_two', title: __('Connection_mobile_two'), operate: 'LIKE',formatter: function (row,index) {
                                return index.connection_mobile_two_see
                            }},
                        {field: 'intention', title: __('Intention'), operate: false},
                        {field: 'staff_name', title: __('Staff_name'), operate: 'LIKE'},
                        {field: 'staff_mobile', title: __('Staff_mobile'), operate: 'LIKE'},
                        {field: 'canal_name', title: __('Canal_name'), operate: 'LIKE'},
                        {field: 'canal_mobile', title: __('Canal_mobile'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table,
                            buttons: [
                                {
                                    name: 'see',
                                    title: __('查看'),
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    text: '查看',
                                    //icon: 'fa fa-folder-o',
                                    url: function(row,column){
                                        var url='show/see?id='+row.id;
                                        return url;
                                    },
                                },
                                {
                                    name: 'follow',
                                    title: __('跟进记录'),
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    text: '跟进记录',
                                    //icon: 'fa fa-folder-o',
                                    url: function(row,column){
                                        var url='follow/index?show_id='+row.id;
                                        return url;
                                    },
                                },
                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
